package com.pkx.cloud.fse7.expand.group.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pkx.cloud.fse7.expand.group.entity.DoorGroup;
import com.pkx.cloud.fse7.expand.group.service.DoorGroupService;
import com.pkx.cloud.whzx.comn.ORpose;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制器
 *
 * @author chenwg
 * @since 2021-04-09
 */
@RestController
@RequestMapping("/group/door-group")
@Api(value = "门禁分组", tags = "门禁分组")
@Slf4j
@ORpose
public class DoorGroupController {

    @Autowired
    private DoorGroupService doorGroupService;

    @ApiOperation("分页列表")
    @GetMapping("/page")
    public Page<DoorGroup> page(Page page, DoorGroup doorGroup) {
        return doorGroupService.pageList(page, doorGroup);
    }

    @ApiOperation("列表")
    @GetMapping("/list")
    public List<DoorGroup> list(DoorGroup doorGroup) {
        return doorGroupService.listByEntity(doorGroup);
    }

    @ApiOperation("详情")
    @GetMapping(value = "/{id}")
    public DoorGroup selectById(@PathVariable("id") String id) {
        return doorGroupService.selectById(id);
    }

    @ApiOperation("新增")
    @PostMapping("")
    public Boolean add(@RequestBody DoorGroup doorGroup) {
        return doorGroupService.saveDoorGroup(doorGroup);
    }

    @ApiOperation("修改")
    @PutMapping("")
    public Boolean modify(@RequestBody DoorGroup doorGroup) {
        return doorGroupService.modify(doorGroup);
    }

    @ApiOperation("删除(单个条目)")
    @DeleteMapping(value = "/{id}")
    public Boolean deleteById(@PathVariable("id") String id) {
        return doorGroupService.deleteById(id);
    }

    @ApiOperation("场地分组树")
    @GetMapping("/getGroupTree")
    public List getGroupTree() {
        return doorGroupService.getYardList();
    }

    @ApiOperation("场地设备树")
    @GetMapping("/getDeviceTree")
    public List getDeviceTree() {
        return doorGroupService.getDeviceTree();
    }

    @GetMapping("/path")
    @ApiOperation("设备列表")
    public List getGroupByPath(String path) {
        return doorGroupService.getGroupByPath(path);
    }

    @PostMapping("/execute")
    public Boolean execute(String triggerId, @RequestBody List<String> list) {
        return doorGroupService.execute(triggerId, list);
    }
}
